package com.xyd.servlet;

import com.xyd.entity.Product;
import com.xyd.service.impl.ProductCategoryServiceImpl;
import com.xyd.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/ProductGetByEpcidServlet")
public class ProductGetByEpcidServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name=new String(request.getParameter("name").getBytes("ISO-8859-1"));
        ProductCategoryServiceImpl productCategoryService = new ProductCategoryServiceImpl();
        ProductServiceImpl productService = new ProductServiceImpl();
        long id=productCategoryService.getIdByName(name);
        int a=(int)id;
        List<Product> list=productService.getProductById(a);
        request.setAttribute("product",list);
        request.getRequestDispatcher("product-list.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
